﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BitPatterns
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] ba = new byte[5] { 1, 2, 39, 4, 5 };
            string pattern = "0100111"; // decimal 39
            StringBuilder sb = new StringBuilder(8 * ba.Length);
            int temp = 0;
            foreach (byte b in ba)
            {
                temp = int.Parse(Convert.ToString(b, 2));
                sb.Append(temp.ToString("00000000"));
            }
            string bitArray = sb.ToString();
            Console.Clear();
            Console.WriteLine("Bitarray is {0}", bitArray);
            Console.WriteLine("Pattern is {0}\n", pattern);
            int index = bitArray.IndexOf(pattern);
            if (index == -1)
                Console.WriteLine("Pattern wasn't found");
            else
                Console.WriteLine("Pattern first occurred at bit {0}", index);
            Console.ReadKey();

            BitWiseOperation bitwise = new BitWiseOperation();
            bitwise.DoXor();
            Console.WriteLine();
            bitwise.Tilde();
            Console.WriteLine();
            bitwise.LeftShift();
            Console.WriteLine();
            bitwise.RightShift();
            Console.ReadKey();
        }
    }
}
